<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript 闭包-全局变量</title>
</head>

<body>
    <!-- 函数可以访问由函数内部定义的变量 -->

    <p>函数可以访问函数内部定义的变量:</p>
    <button type="button" onclick="myFunction()">点我</button>
    <p id="demo"></p>
    <script>
        function myFunction() {
            var a = 4;
            document.getElementById("demo").innerHTML = a * a;
        } 
    </script>
</body>

</html>